home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue49 / Build / hpj2inc.dpr < prev    next >
Encoding:
Text File  |  1999-06-23  |  1.6 KB  |  71 lines

  1. {$APPTYPE CONSOLE}
  2.  
  3. program hpj2inc;
  4.  
  5. uses
  6.   Classes,
  7.   SysUtils,
  8.   IniFiles;
  9.  
  10.   procedure Convert(fNameHPJ, fNameINC: string);
  11.   var
  12.     fINC: text;
  13.     keys: TStringList;
  14.     i: integer;
  15.  
  16.     function Cleanup(s: string): string;
  17.     var
  18.       i: integer;
  19.     begin
  20.       for i := Length(s) downto 1 do
  21.         if not (s[i] in ['A'..'Z','a'..'z','0'..'9','_']) then Delete(s,i,1);
  22.       Result := '_'+s;
  23.     end; { Cleanup }
  24.  
  25.     function Replace(s: string): string;
  26.     var
  27.       p: integer;
  28.     begin
  29.       p := Pos(';',s);
  30.       if p > 0 then begin
  31.         Delete(s,p,1);
  32.         Insert('//',s,p);
  33.       end;
  34.       Result := s;
  35.     end; { Replace }
  36.  
  37.     function Fixup(s: string): string;
  38.     var
  39.       p: integer;
  40.     begin
  41.       p := Pos('//',s);
  42.       if p < 40 then Insert(Copy('                                        ',1,40-p),s,p);
  43.       p := Pos('//',s);
  44.       Insert(';',s,p);
  45.       Result := s;
  46.     end; { Fixup }
  47.     
  48.   begin
  49.     with TIniFile.Create(fNameHPJ) do begin
  50.       try
  51.         keys := TStringList.Create;
  52.         try
  53.           ReadSection('MAP',keys);
  54.           Assign(fINC,fNameINC);
  55.           Rewrite(fINC);
  56.           if keys.Count > 0 then begin
  57.             Writeln(fINC,'const');
  58.             for i := 0 to keys.Count-1 do
  59.               Writeln(fINC,'  ',Fixup(Cleanup(keys[i])+'='+Replace(ReadString('MAP',keys[i],''))));
  60.           end;
  61.           Close(fINC);
  62.         finally keys.Free; end;
  63.       finally Free; end;
  64.     end;
  65.   end; { Convert }
  66.  
  67. begin
  68.   if ParamCount <> 2 then Writeln('Usage: hpj2inc source.hpj dest.inc')
  69.                      else Convert(ParamStr(1),ParamStr(2));
  70. end.
  71.